AddCSLuaFile( "shared.lua" )

SWEP.HoldType = "shotgun"

if ( CLIENT ) then

SWEP.PrintName = "XM1014"
SWEP.Author = "S1L3NT"
SWEP.Slot = 3
SWEP.SlotPos = 1
SWEP.IconLetter = "k"

killicon.AddFont( "weapon_mdm_xm1014", "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) )

end



SWEP.Base = "weapon_mdm_base"

SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.ViewModel = "models/weapons/v_shot_xm1014.mdl"
SWEP.WorldModel = "models/weapons/w_shot_xm1014.mdl"

SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false


SWEP.Primary.Sound = Sound( "Weapon_XM1014.Single" )
SWEP.Primary.Recoil = 10
SWEP.Primary.Damage = 8
SWEP.Primary.NumShots = 8
SWEP.Primary.Cone = 0.07
SWEP.Primary.ClipSize = 8
SWEP.Primary.Delay = 0.25
SWEP.Primary.DefaultClip = 50
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "smg1"

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"


function SWEP:Reload()
	if self.Weapon:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then
		self.Weapon:SetNextPrimaryFire(CurTime() + (self.Primary.ClipSize-self.Weapon:Clip1())*0.5)
		self.Weapon:SetNextSecondaryFire(CurTime() + (self.Primary.ClipSize-self.Weapon:Clip1())*0.5)
		self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START)
	
		if !timer.IsTimer("shells") then
			timer.Create("shells",0.5,self.Primary.ClipSize-self.Weapon:Clip1(),function()
				if self.Owner then	
					self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false )
					self.Weapon:SetClip1(  self.Weapon:Clip1() + 1 )
					self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
				end
			end)
		end
		
		if !timer.IsTimer("finishreload") then
			timer.Create("finishreload",(self.Primary.ClipSize-self.Weapon:Clip1()+1)*0.5,1,function()
				if self.Owner then
					self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH)
				end
				timer.Remove("finishreload")
				timer.Remove("shells")
			end)
		end
	end
end